﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/// <summary>
/// 技能基类，实现技能的冷却、释放等基础逻辑
/// </summary>
public class SkillBase : MonoBehaviour
{

    public float cooldown = 15f;
    protected float lastCastTime = -9999999f;
    public float lastTime = 15f;
    public float cost = 1f;

    //获取剩余冷却时间的方法，可以用于UI显示
    public float getRemainCooldown()
    {
        return (cooldown - (Time.time - lastCastTime)) <= 0 ? 0 : cooldown - (Time.time - lastCastTime);
    }

    public bool isInCooldown()
    {
        Debug.Log(Time.time - lastCastTime);
        return Time.time - lastCastTime < cooldown;
    }

    public IEnumerator SkillCountdown()
    {
        skillStart();
        for (float timer = lastTime; timer >= 0; timer -= Time.deltaTime)
            yield return 0;

        skillEnd();

    }

    //技能释放方法，继承该方法以实现技能释放
    public virtual void Cast()
    {
    }
    //技能开始方法。带有持续时间的技能的开始效果在此实现
    public virtual void skillEnd()
    {

    }
    //技能结束方法。带有持续时间的技能的结束效果在此实现
    public virtual void skillStart()
    {
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
